//
//  MyTravelTableViewCell.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2017/12/20.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "MyTravelTableViewCell.h"
#import "TravelLikeButton.h"
#define collectionBtnW 60

@interface MyTravelTableViewCell()

@property (nonatomic, strong)UIImageView * contentImage;
@property (nonatomic, strong)TravelLikeButton * collectionBtn;
@property (nonatomic, strong)UILabel * titleLabel;
@property (nonatomic, strong)UIButton * draftBtn;
@property (nonatomic, assign)int didID;//游记id、或者美拍id

@end

@implementation MyTravelTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = getColor(@"e5e5e5");
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.contentImage];
        [self.contentView addSubview:self.collectionBtn];
        [self.contentView addSubview:self.titleLabel];
//        [self.contentView addSubview:self.draftBtn];
        
        
    }return self;
}

- (TravelLikeButton *)collectionBtn{
    if (!_collectionBtn) {
        _collectionBtn = [[TravelLikeButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - collectionBtnW - 10, self.titleLabel.top - 10 - 20, collectionBtnW, 20)];
        [_collectionBtn setBackgroundColor:[UIColor clearColor]];
        [_collectionBtn setTitle:@"3321" forState:UIControlStateNormal];
        [_collectionBtn setImage:[UIImage imageNamed:@"icon_shoucang"] forState:UIControlStateNormal];
        [_collectionBtn setImage:[UIImage imageNamed:@"icon_yishoucang"] forState:UIControlStateSelected];
//        [_collectionBtn addTarget:self action:@selector(collectionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }return _collectionBtn;
}

- (UIButton *)draftBtn{
    if (!_draftBtn) {
        _draftBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.collectionBtn.x, self.titleLabel.top - 10 - 20, collectionBtnW, 20)];
        [_draftBtn setImage:[UIImage imageNamed:@"xc_edict"] forState:UIControlStateNormal];
        _draftBtn.backgroundColor = [UIColor clearColor];
        [_draftBtn addTarget:self action:@selector(draftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }return _draftBtn;
}

- (UIImageView *)contentImage{
    if (!_contentImage) {
        _contentImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 171/HEIGHT_5S_SCALE)];
//        _contentImage.backgroundColor = [UIColor redColor];
        _contentImage.image = [UIImage imageNamed:@"img_list2111"];
    }return _contentImage;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.contentImage.bottom, SCREEN_WIDTH, 39/HEIGHT_5S_SCALE)];
        _titleLabel.backgroundColor = [UIColor whiteColor];
        _titleLabel.text = @"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }return _titleLabel;
}

- (void)draftBtnClick{
    
}

- (void)collectionBtnClick:(TravelLikeButton *)btn{
    btn.selected = !btn.selected;
    if (self.delegate) {
        [self.delegate getLikesClickWithDid:self.didID];
    }
}

- (void)setModelData:(MyTravelModelData *)modelData{
    _modelData = modelData;
    [self.contentImage sd_setImageWithURL:[NSURL URLWithString:modelData.pic1]];
    [self.collectionBtn setTitle:modelData.likes forState:UIControlStateNormal];
    self.titleLabel.text = modelData.title;
    self.didID = [modelData.signId intValue];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
